package com.example.myapplication.module1.activity

import android.view.View
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.view.TimePickerView
import com.example.myapplication.R
import com.example.myapplication.databinding.ActivityPlanVisitDetailBinding
import com.example.myapplication.module1.presenter.PlanVisitDetailPresenter
import com.example.myapplication.soaprequest.SoapEnvelop
import com.example.myapplication.soaprequest.request.GetPlanDetailRequest
import com.example.myapplication.soaprequest.request.SoapRequestBody
import com.example.myapplication.widget.CustomerToolbar
import com.example.mylibrary.base.BaseMvpActivity
import com.lxj.xpopup.impl.LoadingPopupView
import java.text.SimpleDateFormat
import java.util.*

/**
 * 呼叫中心
 */
class PlanVisitDetailActivity :
    BaseMvpActivity<PlanVisitDetailActivity, PlanVisitDetailPresenter, ActivityPlanVisitDetailBinding>() {
    lateinit var loadPopup: LoadingPopupView
    private var pvTime: TimePickerView? = null
    private var dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA)
    private var curPage = 1
    private val getPlanDetailRequest = GetPlanDetailRequest()
    private val soapRequestBody = SoapRequestBody()
    private val soapEnvelop = SoapEnvelop()

    override fun getPresenter(): PlanVisitDetailPresenter = PlanVisitDetailPresenter()

    override fun getBinding(): ActivityPlanVisitDetailBinding {
        return ActivityPlanVisitDetailBinding.inflate(layoutInflater)
    }

    override fun initData() {
    }

    override fun initView() {
        loadPopup = builder.asLoading("加载中...")
        viewBinding.clToolbar.setTitle(getString(R.string.choosePlan))
        viewBinding.clToolbar.clickListener = object : CustomerToolbar.ClickListener {
            override fun onBackListener() {
                finish()
            }

            override fun onRightListener() {
            }
        }

        viewBinding.tvDate.setOnClickListener(this)
        viewBinding.tvSearch.setOnClickListener(this)

        //时间选择器
        pvTime = TimePickerBuilder(this) { date, _ ->
            viewBinding.tvDate.text = dateFormat.format(date)
        }
            .setType(booleanArrayOf(true, true, true, false, false, false))
            .build()
    }

    override fun onClick(p0: View?) {
        when (p0?.id) {
            R.id.tvDate -> {
                pvTime?.show()
            }
            R.id.tvSearch -> {

            }
        }
    }

    private fun getPlanList() {
        if (curPage == 1) {
//            tempPlanBeanList.clear()
        }
        getPlanDetailRequest.curpage = "$curPage"
        getPlanDetailRequest.rq = ""
        getPlanDetailRequest.zt = ""
        getPlanDetailRequest.filter = ""
        getPlanDetailRequest.jhbid = ""
        soapRequestBody.value = getPlanDetailRequest
        soapEnvelop.body = soapRequestBody
        mPresenter?.getPlanList(soapEnvelop)
    }

    fun showLoad() {
        if (!viewBinding.list.srlRefresh.isRefreshing && !viewBinding.list.srlRefresh.isLoading) {
            loadPopup.show()
        }
    }

    fun dismissLoad() {
        loadPopup.dismiss()
        if (viewBinding.list.srlRefresh.isRefreshing || viewBinding.list.srlRefresh.isLoading) {
            viewBinding.list.srlRefresh.finishRefresh()
            viewBinding.list.srlRefresh.finishLoadMore()
        }
    }

    fun setPlanDetail(result: String) {

    }

}
